package cn.tedu.imop.marketing.dao.repository.impl;

import cn.tedu.imop.common.context.PageContext;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.common.utils.PageInfoToPageDataConverter;
import cn.tedu.imop.marketing.dao.mapper.CouponMapper;
import cn.tedu.imop.marketing.dao.repository.CouponRepository;
import cn.tedu.imop.marketing.entity.Coupon;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class CouponRepositoryImpl implements CouponRepository{
    private CouponMapper couponMapper;
    public CouponRepositoryImpl(CouponMapper couponMapper) {
        this.couponMapper = couponMapper;
    }
    @Override
    public int insertCoupon(Coupon coupon) {
        return couponMapper.insert(coupon);
    }
    @Override
    public PageData<Coupon> selectCouponList(Coupon coupon) {
        PageContext.startPage();
        List<Coupon> coupons = couponMapper.selectList(coupon);
        log.debug("coupons:{}",coupons);
        return PageInfoToPageDataConverter.convert(new PageInfo<>(coupons));
    }
}
